import request from '/@/utils/request';
import { useUrlUtil } from '/@/utils/urlUtil';
import { BaseRequest } from '/@/interfaces/BaseModel';
import { BaseResponse } from '/@/interfaces/BaseModel';
import { UserInfoApi } from '/@/enums/jdfsystem-api-enum';
import {
    UserInfoSearchParamModel,
    UserInfoListModel,
    UserInfoDetailModel,
    UserInfoAddParamModel,
    UserInfoEditParamModel,
    UserInfoDeleteParamModel,
    LoginPramModel,
    CaptchaModel,
    CaptchaParamModel,
} from '/@/interfaces/JdfsystemModel';

function useUserInfo() {
    return {
        login: function (payload: BaseRequest<LoginPramModel>) {
            return request.post<BaseResponse<string>>(UserInfoApi.LOGIN, payload);
        },
        list: function (payload: BaseRequest<UserInfoSearchParamModel>) {
            return request.post<BaseResponse<UserInfoListModel[]>>(UserInfoApi.LIST, payload);
        },
        detailByCurrent: function () {
            return request.get<BaseResponse<UserInfoDetailModel>>(UserInfoApi.DETAIL_BY_CURRENT);
        },
        detail: function (payload: Object) {
            const useUrl = useUrlUtil();
            return request.get<BaseResponse<UserInfoDetailModel>>(useUrl.joinParam(UserInfoApi.DETAIL, payload));
        },
        add: function (payload: BaseRequest<UserInfoAddParamModel>) {
            return request.post<BaseResponse<boolean>>(UserInfoApi.ADD, payload);
        },
        edit: function (payload: BaseRequest<UserInfoEditParamModel>) {
            return request.post<BaseResponse<boolean>>(UserInfoApi.EDIT, payload);
        },
        del: function (payload: BaseRequest<UserInfoDeleteParamModel>) {
            return request.post<BaseResponse<boolean>>(UserInfoApi.DEL, payload);
        },
        captcha: function (payload: BaseRequest<CaptchaParamModel>) {
            const useUrl = useUrlUtil();
            return request.get<BaseResponse<CaptchaModel>>(useUrl.joinParam(UserInfoApi.CAPTCHA, payload));
        },

    };
}

export default useUserInfo;